<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="copyright" content="All Rights Reserved, Copyright (C) 2013, Wuyeguo, Ltd."/>
    <title>智能应急快速搭建平台V1.0</title>
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <script type="text/javascript" src="../../js/commonJs.js"></script>
</head>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar-md">
        <div class="wu-toolbar-button">
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAdd()" plain="true">添加</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="remove()" plain="true">删除</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="publish()" plain="true">发布</a>
        </div>
<!--        <div class="wu-toolbar-search">-->
<!--            <label>模版id：</label><input id="id" class="wu-text" style="width:100px">-->
<!--            <label>模版名称：</label><input id="name" class="wu-text" style="width:100px">-->
<!--            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="doSearch()">开始检索</a>-->
<!--        </div>-->
    </div>
    <!-- End of toolbar -->
    <table id="wu-datagrid-md" class="easyui-datagrid" toolbar="#wu-toolbar-md"></table>
</div>
<!-- Begin of easyui-dialog -->
<div id="wu-dialog-md" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:1100px; height:600px; padding:10px;">

</div>
<!-- End of easyui-dialog -->
<script type="text/javascript">

    /**
     * Name 查询
     */
    function doSearch(){
        var paramData = {
            id: $('#id').val(),
            name: $('#name').val()
        };
        $('#wu-datagrid-md').datagrid('load',{paramData:JSON.stringify(paramData)});
    }


	/**
	* Name 添加记录
	*/
	function add(){
		$('#wu-form-md').form('submit', {
			url:'',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-md').dialog('close');
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	* Name 修改记录
	*/
	function edit(){
		$('#wu-form-md').form('submit', {
			url:'',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#wu-dialog-md').dialog('close');
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	* Name 删除记录
	*/
	function remove(){
		$.messager.confirm('信息提示','确定要删除该记录？', function(result){
			if(result){
				var items = $('#wu-datagrid-md').datagrid('getSelected');
				var ids = [];
				$(items).each(function(){
					ids.push(this.id);
				});
				//alert(ids);return;
				$.ajax({
					url:'/activiti/deleteByIds',
					data:'ids='+ids,
					success:function(data){
						if(data){
							$.messager.alert('信息提示','删除成功！','info');
                            $('#wu-datagrid-md').datagrid();
						}
						else
						{
							$.messager.alert('信息提示','删除失败！','info');		
						}
					}	
				});
			}	
		});
	}

    function publish(){
        $.messager.confirm('信息提示','确定发布？', function(result){
            if(result){
                var items = $('#wu-datagrid-md').datagrid('getSelected');
                var ids = [];
                $(items).each(function(){
                    ids.push(this.id);
                });
                $.ajax({
                    url:'/activiti/publish',
                    data:'modelId='+ids,
                    success:function(data){
                        if(data){
                            $.messager.alert('信息提示','发布成功！','info');
                            $('#wu-datagrid-md').datagrid();
                        }
                        else
                        {
                            $.messager.alert('信息提示','发布失败！','info');
                        }
                    }
                });
            }
        });

    }


	/**
	* Name 打开添加窗口
	*/
	function openAdd(){
		$('#wu-form-md').form('clear');
		$('#wu-dialog-md').dialog({
           // href: '/activiti/create',
            content:"<iframe id='modeler' scrolling='auto' frameborder='0' src='/activiti/create' style='width:100%; height:100%; display:block;'></iframe>",
			closed: false,
			modal:true,
            title: "添加模型"
        });
	}
	
	/**
	* Name 打开修改窗口
	*/
	function openEdit(id){
		$('#wu-form-md').form('clear');
		//var item = $('#wu-datagrid-md').datagrid('getSelected');
        //var id = item.id;
		$('#wu-dialog-md').dialog({
            content:"<iframe id='modeler1' scrolling='auto' frameborder='0' src='/activiti/editor?modelId="+id+"' style='width:100%; height:100%; display:block;'></iframe>",
            closed: false,
			modal:true,
            title: "修改模型"
        });
	}	

	/**
	* Name 载入数据
	*/
	$('#wu-datagrid-md').datagrid({
        url:'/activiti/list1',
		rownumbers:true,
		pageSize:20,
		pagination:true,
        //如果为true，该复选框被选中/取消选中，当用户点击某一行上。如果为false，该复选框仅检查/取消选中，当用户点击完全的复选框。
        checkOnSelect:false,
		fitColumns:true,
		fit:true,
        pageList: [10, 20, 50, 100, 150, 200],
        columns:[[
			{ checkbox:true},
			{ field:'id',title:'id',width:100,sortable:true,align:'center'},
            { field:'name',
                title:'模版名称',
                width:100,sortable:true,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" href="javascript:openEdit(\''+data.id+'\')">' + data.name + '</a>';
                }
            },
			{ field:'createTime',title:'创建时间',width:180,sortable:true,align:'center'},
			{ field:'lastUpdateTime',title:'更新时间',width:100,align:'center'},
            { field:'deploymentId',title:'流程id',width:100,align:'center'},
			{ field:'version',
                title:'版本号',
                width:100,
                align:'center',
                formatter: function (value, data) {
                    return '<a style="color: blue;" >V' + data.version + '.0</a>';
                }
			}
		]]
	});
</script>